#include <iostream>
#include "../glog/gloghelper.h"
using namespace std;
#ifdef _DEBUG
#pragma comment(lib, "opencv_aruco320d.lib")
#pragma comment(lib, "opencv_bgsegm320d.lib")
#pragma comment(lib, "opencv_bioinspired320d.lib")
#pragma comment(lib, "opencv_calib3d320d.lib")
#pragma comment(lib, "opencv_ccalib320d.lib")
#pragma comment(lib, "opencv_core320d.lib")
#pragma comment(lib, "opencv_datasets320d.lib")
#pragma comment(lib, "opencv_dnn320d.lib")
#pragma comment(lib, "opencv_dpm320d.lib")
#pragma comment(lib, "opencv_face320d.lib")
#pragma comment(lib, "opencv_features2d320d.lib")
#pragma comment(lib, "opencv_flann320d.lib")
#pragma comment(lib, "opencv_fuzzy320d.lib")
#pragma comment(lib, "opencv_hdf320d.lib")
#pragma comment(lib, "opencv_highgui320d.lib")
#pragma comment(lib, "opencv_imgcodecs320d.lib")
#pragma comment(lib, "opencv_imgproc320d.lib")
#pragma comment(lib, "opencv_line_descriptor320d.lib")
#pragma comment(lib, "opencv_ml320d.lib")
#pragma comment(lib, "opencv_objdetect320d.lib")
#pragma comment(lib, "opencv_optflow320d.lib")
#pragma comment(lib, "opencv_phase_unwrapping320d.lib")
#pragma comment(lib, "opencv_photo320d.lib")
#pragma comment(lib, "opencv_plot320d.lib")
#pragma comment(lib, "opencv_reg320d.lib")
#pragma comment(lib, "opencv_rgbd320d.lib")
#pragma comment(lib, "opencv_saliency320d.lib")
#pragma comment(lib, "opencv_shape320d.lib")
#pragma comment(lib, "opencv_stereo320d.lib")
#pragma comment(lib, "opencv_stitching320d.lib")
#pragma comment(lib, "opencv_structured_light320d.lib")
#pragma comment(lib, "opencv_superres320d.lib")
#pragma comment(lib, "opencv_surface_matching320d.lib")
#pragma comment(lib, "opencv_text320d.lib")
#pragma comment(lib, "opencv_tracking320d.lib")
#pragma comment(lib, "opencv_ts320d.lib")
#pragma comment(lib, "opencv_video320d.lib")
#pragma comment(lib, "opencv_videoio320d.lib")
#pragma comment(lib, "opencv_videostab320d.lib")
#pragma comment(lib, "opencv_xfeatures2d320d.lib")
#pragma comment(lib, "opencv_ximgproc320d.lib")
#pragma comment(lib, "opencv_xobjdetect320d.lib")
#pragma comment(lib, "opencv_xphoto320d.lib")
#else
#pragma comment(lib, "opencv_aruco320.lib")
#pragma comment(lib, "opencv_bgsegm320.lib")
#pragma comment(lib, "opencv_bioinspired320.lib")
#pragma comment(lib, "opencv_calib3d320.lib")
#pragma comment(lib, "opencv_ccalib320.lib")
#pragma comment(lib, "opencv_core320.lib")
#pragma comment(lib, "opencv_datasets320.lib")
#pragma comment(lib, "opencv_dnn320.lib")
#pragma comment(lib, "opencv_dpm320.lib")
#pragma comment(lib, "opencv_face320.lib")
#pragma comment(lib, "opencv_features2d320.lib")
#pragma comment(lib, "opencv_flann320.lib")
#pragma comment(lib, "opencv_fuzzy320.lib")
#pragma comment(lib, "opencv_hdf320.lib")
#pragma comment(lib, "opencv_highgui320.lib")
#pragma comment(lib, "opencv_imgcodecs320.lib")
#pragma comment(lib, "opencv_imgproc320.lib")
#pragma comment(lib, "opencv_line_descriptor320.lib")
#pragma comment(lib, "opencv_ml320.lib")
#pragma comment(lib, "opencv_objdetect320.lib")
#pragma comment(lib, "opencv_optflow320.lib")
#pragma comment(lib, "opencv_phase_unwrapping320.lib")
#pragma comment(lib, "opencv_photo320.lib")
#pragma comment(lib, "opencv_plot320.lib")
#pragma comment(lib, "opencv_reg320.lib")
#pragma comment(lib, "opencv_rgbd320.lib")
#pragma comment(lib, "opencv_saliency320.lib")
#pragma comment(lib, "opencv_shape320.lib")
#pragma comment(lib, "opencv_stereo320.lib")
#pragma comment(lib, "opencv_stitching320.lib")
#pragma comment(lib, "opencv_structured_light320.lib")
#pragma comment(lib, "opencv_superres320.lib")
#pragma comment(lib, "opencv_surface_matching320.lib")
#pragma comment(lib, "opencv_text320.lib")
#pragma comment(lib, "opencv_tracking320.lib")
#pragma comment(lib, "opencv_ts320.lib")
#pragma comment(lib, "opencv_video320.lib")
#pragma comment(lib, "opencv_videoio320.lib")
#pragma comment(lib, "opencv_videostab320.lib")
#pragma comment(lib, "opencv_xfeatures2d320.lib")
#pragma comment(lib, "opencv_ximgproc320.lib")
#pragma comment(lib, "opencv_xobjdetect320.lib")
#pragma comment(lib, "opencv_xphoto320.lib")
#endif
#include "../libCVMiscellaneous/CVMiscellaneous.h"
#pragma comment(lib, "libCVMiscellaneousd.lib")


#define rowPtr(imagePtr, dataType, lineIndex) \
	    (dataType *)(imagePtr->imageData + (lineIndex) * imagePtr->widthStep)

int main(int argc, char* argv[])
{
	GLogHelper logger(argv[0]);

	char* path = R"(D:\projects\TestConsole\TestConsole\test.jpg)";

	char *imagefile = path;

	IplImage *image = cvLoadImage(imagefile);

	if (image == NULL)
	{
		std::cout << "image error: " << imagefile << std::endl << std::flush;
		return -1;
	}

	// show an image
	cvShowImage("original", image);

	
	
	// specify a line to plot
	int the_line = 100;

	auto plotter = IPlotter::GetPlotter();

	int key = -1;
	while (the_line < image->height)
	{
		unsigned char *pb = rowPtr(image, unsigned char, the_line);
		int width = image->width;


		//CvPlot::plotFigure("RGB", pb + 0, width, 3, -1, -1, -1, "B");
		//CvPlot::plotFigure("RGB", pb + 1, width, 3, -1, -1, -1, "G");
		//CvPlot::plotFigure("RGB", pb + 2, width, 3, -1, -1, -1, "R");

		cv::Mat m;
		plotter->plotUchar("RGB", pb + 0, width, 3, -1, -1, -1, "B");
		plotter->plotUchar("RGB", pb + 1, width, 3);
		m = plotter->plotUchar("RGB", pb + 2, width, 3, -1, -1, -1, "R");

		cv::imshow("rgb", m);
		key = cvWaitKey(0);

		if (key == 32)
		{
			// plot the next line
			the_line++;
			// clear previous plots
			plotter->clear("RGB");
		}
		else
		{
			break;
		}
	}

	cvReleaseImage(&image);




	return 0;
}